const Monitor = require('../../utils/monitor.js').Monitor
const util = require('../../utils/util.js')
Page(Monitor.hookApp({
  data: {
    imgUrls: getApp().globalData.imgUrls,
    idx:0,
    indexs:0,
    bigArr: [], //展示用的数组
    liuyanHidden: false, //留言展示隐藏
    liuyanVal: '', //留言内容
    isFalse: false, //是否提现失败
    imgUrl: getApp().globalData.imgUrl,
    isOpen: false, //箭头方向  
    hiddenIsShow: false, //控制下拉
    progress: 0, //进度
    dateBegin: '请选择时间',
    fakeTime: '2015-5-5'
  },
  getData(time) {
    util.API('spwx/v1.Distribut/cashLog',time).then(res => {
      let {
        code,
        data,
        msg
      } = res
      let bigArr = []
      if (code == 200) {
        let total = data.total
        delete data.total
        for (let prop in data) {
          let arr = []
          let month = [prop]
          arr[0] = [month, data[prop].cashmoney]
          delete data[prop].cashmoney
          arr[1] = data[prop];
          let innerArr = []
          for (let props in arr[1]) {
            arr[1][props].isOpen = false
            innerArr.push(arr[1][props])
          }
          arr[1] = innerArr
          bigArr.push(arr)
        }
        this.setData({
          total
        })
        console.log(this.data.bigArr)
      }else{
      wx.showToast({
        title: msg + '',
        icon:'none'
      })
      }
      this.setData({
        bigArr
      })
    })
  },




  changeJianTou(e) { //改变箭头方向
    let idx = e.currentTarget.dataset.idx, // 几月份的角标
      indexs = e.currentTarget.dataset.indexs, // 点击的是第几个
      isOpen = this.data.bigArr[idx][1][indexs].isOpen
    this.data.bigArr[idx][1][indexs].isOpen = !isOpen
    this.setData({
      idx,
      indexs,
      bigArr: this.data.bigArr
    })
  },


  


  liuyanHidden() {
    let bigArr = this.data.bigArr,
       idx = this.data.idx,
       indexs = this.data.indexs;
    this.setData({
      liuyanHidden: !this.data.liuyanHidden,
      liuyanVal: bigArr[idx][1][indexs].remarks
    })
  },
  bindDateChange(e) { // picker组件变换赋值
    var val = e.detail.value,
      that = this,
      idx = e.currentTarget.dataset.idx //0为起始时间 1为结束时间
    if (idx == 0) {
      this.setData({
        dateBegin: val
      })
    } else if (idx == 1) {
      this.setData({
        dateFinish: val
      })
    }
    if (this.data.dateBegin != "请选择时间" && this.data.dateFinish) { //验证前后时间对比
      var b = Date.parse(this.data.dateBegin)
      var f = Date.parse(this.data.dateFinish)
      if (b > f) {
        wx.showModal({
          title: '提示',
          content: '开始时间不能超过结束时间',
          showCancel: false,
          success(res) {
            if (!res.cancel) {
              that.reSet()
            }
          }
        })
      }
    }
    console.log(this.data.dateBegin, this.data.dateFinish)
    let json = {
      stime:this.data.dateBegin == '请选择时间' ? '' : this.data.dateBegin,
      etime: `${this.data.dateFinish ? this.data.dateFinish:this.data.nowDate} 23:59:59`
    }
    this.getData(json)
  },
  hiddenIsShow() { //隐藏部分显示
    this.setData({
      hiddenIsShow: !this.data.hiddenIsShow,
    })
  },
  reSet() { //重置时间
    this.setData({
      dateBegin: '请选择时间',
      dateFinish: this.data.nowDate
    })
  },
  onLoad: function(options) {
    //设置时间
    var date = new Date()
    var y = date.getFullYear(),
      m = date.getMonth(),
      d = date.getDate();
    if (d < 10) {
      d = '0' + d
    }
    this.setData({
      nowDate: y + '-' + (m + 1) + '-' + d
    })
    //设置时间结束
  },
  onShow() {
    this.getData()
  }
}))